home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7983 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.7 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is &Variable (declared as: char Variable[10])?
  5. Date: 28 Feb 1996 11:06:15 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4h2937INN8gb@anvil.ugrad.cs.ubc.ca>
  8. References: <4gqpa1$3h9@alcor.usc.edu> <4gtab6$acb@ceylon.gte.com> <313318b8.53776146@nntp.ix.netcom.com> <4h1u9d$sqq@ceylon.gte.com>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <4h1u9d$sqq@ceylon.gte.com>, Brenda  <g051286> wrote:
  12.  
  13.  >What is the definition of a pointer?  I have always been taught that a
  14.  
  15. A pointer is an object which holds the address of another object.
  16.  
  17.  >pointer is simply an address in memory, and an array name (i.e. myarray)
  18.  >is simply a CONSTANT address.  I don't think this statement is all that
  19.  
  20. An array _has_ a constant address. But it an address it is not. It's not a
  21. pointer because an array is not an object which holds the address of
  22. another object. It can have elements which are pointers, of course.
  23.  
  24.  >radical.  Of course there are differences between arrays and pointers
  25.  
  26. Well, it is radical, because what is understood by ``constant'' in C is different
  27. from what you mean. A constant is an object which holds a value that is
  28. initialized once but doesn't change. You designate this by modifying its type
  29. with a ``const'' attribute. Another meaning of ``constant'' is ``literal
  30. constant''---a number, character or string literal. A third meaning is
  31. ``pre-processor constant''.
  32.  
  33.  >due to the fact that an array is a CONSTANT address and a pointer is a
  34.  >VARIABLE address.  And the reason I said you shouldn't (note shouldn't
  35.  >not couldn't) say &myarray is:
  36.  
  37.  >
  38.  >==================================================
  39.  >(from "A Book On C", Kelley & Pohl, pg 200)
  40.  >Constructs not to be pointed at:
  41.  >1. Do not point at constants. (&3)
  42.  >2. Do not point at arrays; an array name is a constant. (int a[77]; &a)
  43.  
  44. If this book was written after the publication of K&R2, it should be considered
  45. poorly researched. Sell this book immediately.
  46.  
  47. An array name is not a constant, it is the name of an array object. The C
  48. language has no true constants like Pascal, it only has pre-processor
  49. constants, literals, and variables that can be initialized but not assigned to
  50. (const qualifier).
  51.  
  52. Pointing at arrays is valid, and an important feature of ANSI C.
  53.  
  54.  >3. Do not point at ordinary expressions &(k + 99)
  55.  
  56. This is stupid, because it suggests that the assertion supports a
  57. counterfactual; i.e. that you _can_ point at such expressions, but that you
  58. _shouldn't_. In fact, the compiler will reject that, depending on the type of
  59. expression.
  60.  
  61. There is no such thing as ``ordinary expression''; the introduction of such at
  62. term is misleading.
  63.  
  64.  >4. Do not point at register variables. (register v; &v)
  65.  
  66. Compilers will reject this. Again, this is something that you simply cannot do.
  67.  
  68. What is the point of including things that cannot be done in a list of things
  69. that shouldn't be done? The authors clearly lack the intellectual rigor to be
  70. writing about matters related to computer science.
  71.  
  72.  >The address operator can be applied to variables and array elements.
  73.  
  74. This contradicts their earlier assertion that it cannot be applied to arrays,
  75. which are variables. It can also be applied to functions.
  76.  
  77.  >===================================================
  78.  >
  79.  >So again I say, myarray is DEFINITELY a pointer (i.e. address in memory).
  80.  
  81. According to your book. Not all that is printed is the truth.
  82.  
  83.  
  84. If myarray is a pointer to char, why is it not the case that
  85.  
  86.     char myarray[131];
  87.     
  88.     if (sizeof(myarray) == sizeof(char *)) 
  89.         puts("Yes!\n");
  90.  
  91. fails to produce a Yes? Would not two pointers to char have the same size?
  92. -- 
  93.  
  94.